String clazzTpl({package}) => """
import 'app_debug_model.dart';
import 'package:xanno/xanno.dart';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:path_provider/path_provider.dart';
import 'package:$package/mixin/base_widget_mixin.dart';
import 'package:$package/debug/slice/actions.dart';
import 'package:$package/widget/base_store_container.dart';

@GRoute(url: '/appDebug', title: 'AppDebug')
class AppDebugPage extends StatelessWidget {
  final String title;

  const AppDebugPage({Key? key, required this.title}) : super(key: key);

  Widget trailing(ThemeState theme, AppDebugModel item) {
    switch (item.key) {
      case AppDebugKey.documentDir:
        return Icon(Icons.keyboard_arrow_right, size: 30, color: theme.body);
      case AppDebugKey.proxy:
        return Icon(Icons.extension, size: 30, color: theme.body);
      case AppDebugKey.websocket:
        return Icon(Icons.account_tree, size: 30, color: theme.body);
      case AppDebugKey.hosts:
        return Icon(Icons.electrical_services, size: 30, color: theme.body);
      case AppDebugKey.h5FaceHosts:
        return Icon(Icons.face_rounded, size: 30, color: theme.body);
      case AppDebugKey.themes:
        return Icon(Icons.wb_incandescent_rounded, size: 30, color: theme.body);
      case AppDebugKey.cleanMock:
        return Icon(Icons.refresh_rounded, size: 30, color: theme.body);
      case AppDebugKey.programMode:
        return Icon(Icons.all_inclusive_rounded, size: 30, color: theme.body);
      case AppDebugKey.jsCoreMode:
        return Icon(Icons.album_rounded, size: 30, color: theme.body);
      default:
        return CupertinoSwitch(
          activeColor: Colors.green,
          trackColor: theme.body.withOpacity(0.8),
          value: item.on,
          onChanged: (bool value) {
            item.on = !item.on;
            StaticStore.store!.state.appConfigState!.updateAppDebug(item);
          },
        );
    }
  }

  Widget subtitle(ThemeState theme, AppDebugModel item) {
    String descT = '';
    switch (item.key) {
      case AppDebugKey.proxy:
        String? desc = item.desc;
        String? port = item.port;
        if (desc?.isEmpty ?? true) {
          desc = '地址(例:192.168.0.1)';
        }
        if (port?.isEmpty ?? true) {
          port = '端口(例:8888)';
        }
        descT = "\$desc: \$port";
        break;
      case AppDebugKey.websocket:
        String? desc = item.desc;
        if (desc?.isEmpty ?? true) {
          desc = '地址(例:ws://192.168.0.1:8080/syws)';
        }
        descT = desc ?? "";
        break;
      case AppDebugKey.hosts:
        DataModel selectHost =
            item.childList!.firstWhere((element) => element.isDef);
        descT = "\${selectHost.key}: \${selectHost.value}";
        break;
      case AppDebugKey.h5FaceHosts:
        DataModel selectHost =
            item.childList!.firstWhere((element) => element.isDef);
        descT = "\${selectHost.key}: \${selectHost.value}";
        break;
      case AppDebugKey.themes:
        DataModel selectTheme =
            item.childList!.firstWhere((element) => element.isDef);
        descT = "当前主题:\${selectTheme.key}";
        break;
      case AppDebugKey.cleanMock:
        descT = "清空本地 mock db";
        break;
      case AppDebugKey.programMode:
        DataModel selectTheme =
            item.childList!.firstWhere((element) => element.isDef);
        descT = "当前模式:\${selectTheme.key}";
        break;
      case AppDebugKey.jsCoreMode:
        DataModel selectTheme =
            item.childList!.firstWhere((element) => element.isDef);
        descT = "当前模式:\${selectTheme.key}";
        break;
      default:
        descT = '\${item.on ? '开启' : '关闭'}功能';
        break;
    }
    return Text(
      descT,
      style: TextStyle(color: theme.body),
    );
  }

  void onTap(BuildContext context, AppDebugModel item) async {
    switch (item.key) {
      case AppDebugKey.documentDir:
        final navigator = Navigator.of(context);
        final dir = await getApplicationDocumentsDirectory();
        navigator.pushNamed(RouteConstant.AppErrorLogPage,
            arguments: ErrorLogFileModel(
                path: dir.path, title: '文档目录', isFile: false));
        break;
      case AppDebugKey.proxy:
        showCupertinoDialog(
            context: context,
            builder: (context) {
              return CupertinoAlertDialog(
                content: Column(
                  children: [
                    CupertinoTextField(
                      controller: TextEditingController(text: item.desc),
                      prefix: const Text('代理地址:'),
                      placeholder: '输入代理地址',
                      onChanged: (value) {
                        item.desc = value;
                      },
                    ),
                    const SizedBox(height: 10),
                    CupertinoTextField(
                      controller: TextEditingController(text: item.port),
                      prefix: const Text('端口:'),
                      placeholder: '输入端口',
                      onChanged: (value) {
                        item.port = value;
                      },
                    ),
                  ],
                ),
                actions: [
                  CupertinoDialogAction(
                    child: const Text('取消'),
                    onPressed: () => Navigator.pop(context),
                  ),
                  CupertinoDialogAction(
                    child: const Text('确定'),
                    onPressed: () {
                      StaticStore.store!.state.appConfigState!
                          .updateAppDebug(item);
                      Navigator.pop(context);
                    },
                  ),
                ],
              );
            });
        break;
      case AppDebugKey.websocket:
        showCupertinoDialog(
            context: context,
            builder: (context) {
              return CupertinoAlertDialog(
                content: Column(
                  children: [
                    CupertinoTextField(
                      controller: TextEditingController(text: item.desc),
                      prefix: const Text('地址:'),
                      placeholder: '输入地址',
                      onChanged: (value) {
                        item.desc = value;
                      },
                    ),
                  ],
                ),
                actions: [
                  CupertinoDialogAction(
                    child: const Text('取消'),
                    onPressed: () => Navigator.pop(context),
                  ),
                  CupertinoDialogAction(
                    child: const Text('确定'),
                    onPressed: () {
                      StaticStore.store!.state.appConfigState!
                          .updateAppDebug(item);
                      Navigator.pop(context);
                    },
                  ),
                ],
              );
            });
        break;
      case AppDebugKey.hosts:
        if (item.childList == null) return;
        showCupertinoModalPopup(
            context: context,
            builder: (context) {
              return CupertinoActionSheet(
                title: const Text('切换app服务,切换后重启'),
                actions: item.childList!.map<Widget>((e) {
                  return CupertinoActionSheetAction(
                    onPressed: () {
                      item.childList = item.childList!.map((e1) {
                        e1.isDef = (e1.value == e.value);
                        return e1;
                      }).toList();
                      StaticStore.store!.state.appConfigState!
                          .updateAppDebug(item);
                      Navigator.pop(context);
                    },
                    child: Text(
                      "\${e.key}: \${e.value}",
                      style: const TextStyle(fontSize: 12),
                    ),
                  );
                }).toList(),
                cancelButton: CupertinoActionSheetAction(
                  onPressed: () => Navigator.pop(context),
                  child: const Text('取消'),
                ),
              );
            });
        break;
      case AppDebugKey.h5FaceHosts:
        if (item.childList == null) return;
        showCupertinoModalPopup(
            context: context,
            builder: (context) {
              return CupertinoActionSheet(
                title: const Text('切换H5人脸认证服务,切换后重启'),
                actions: item.childList!.map<Widget>((e) {
                  return CupertinoActionSheetAction(
                    onPressed: () {
                      item.childList = item.childList!.map((e1) {
                        e1.isDef = (e1.value == e.value);
                        return e1;
                      }).toList();
                      StaticStore.store!.state.appConfigState!
                          .updateAppDebug(item);
                      Navigator.pop(context);
                    },
                    child: Text(
                      "\${e.key}: \${e.value}",
                      style: const TextStyle(fontSize: 12),
                    ),
                  );
                }).toList(),
                cancelButton: CupertinoActionSheetAction(
                  onPressed: () => Navigator.pop(context),
                  child: const Text('取消'),
                ),
              );
            });
        break;
      case AppDebugKey.themes:
        if (item.childList == null) return;
        showCupertinoModalPopup(
            context: context,
            builder: (context) {
              return CupertinoActionSheet(
                title: const Text('切换主题'),
                actions: item.childList!.map<Widget>((e) {
                  return CupertinoActionSheetAction(
                    onPressed: () {
                      item.childList = item.childList!.map((e1) {
                        e1.isDef = (e1.value == e.value);
                        if (e1.isDef) {
                          StaticStore.store!.dispatch(ThemeActions.updateTheme(
                              ThemeState.formatThemeType(e1.value)));
                        }
                        return e1;
                      }).toList();
                      StaticStore.store!.state.appConfigState!
                          .updateAppDebug(item);
                      Navigator.pop(context);
                    },
                    child: Text(
                      "\${e.key}: \${e.value}",
                      style: const TextStyle(fontSize: 12),
                    ),
                  );
                }).toList(),
                cancelButton: CupertinoActionSheetAction(
                  onPressed: () => Navigator.pop(context),
                  child: const Text('取消'),
                ),
              );
            });
        break;
      case AppDebugKey.cleanMock:
        showCupertinoDialog(
            context: context,
            builder: (context) {
              return CupertinoAlertDialog(
                content: Text(item.title),
                actions: [
                  CupertinoDialogAction(
                    child: const Text('取消'),
                    onPressed: () => Navigator.pop(context),
                  ),
                  CupertinoDialogAction(
                    child: const Text('确定'),
                    onPressed: () async {
                      // bool boo = await MockDao.deleteAll();
                      // Toast.show(boo ? "清空成功" : "清空失败");
                      Navigator.pop(context);
                    },
                  ),
                ],
              );
            });
        break;
      case AppDebugKey.programMode:
        if (item.childList == null) return;
        showCupertinoModalPopup(
            context: context,
            builder: (context) {
              return CupertinoActionSheet(
                title: const Text('小程序模式切换'),
                actions: item.childList!.map<Widget>((e) {
                  return CupertinoActionSheetAction(
                    onPressed: () {
                      item.childList = item.childList!.map((e1) {
                        e1.isDef = (e1.value == e.value);
                        return e1;
                      }).toList();
                      StaticStore.store!.state.appConfigState!
                          .updateAppDebug(item);
                      Navigator.pop(context);
                    },
                    child: Text(
                      "\${e.key}: \${e.value}",
                      style: const TextStyle(fontSize: 12),
                    ),
                  );
                }).toList(),
                cancelButton: CupertinoActionSheetAction(
                  onPressed: () => Navigator.pop(context),
                  child: const Text('取消'),
                ),
              );
            });
        break;
      case AppDebugKey.jsCoreMode:
        if (item.childList == null) return;
        showCupertinoModalPopup(
            context: context,
            builder: (context) {
              return CupertinoActionSheet(
                title: const Text('JSCore模式切换'),
                actions: item.childList!.map<Widget>((e) {
                  return CupertinoActionSheetAction(
                    onPressed: () {
                      item.childList = item.childList!.map((e1) {
                        e1.isDef = (e1.value == e.value);
                        return e1;
                      }).toList();
                      StaticStore.store!.state.appConfigState!
                          .updateAppDebug(item);
                      Navigator.pop(context);
                    },
                    child: Text(
                      "\${e.key}: \${e.value}",
                      style: const TextStyle(fontSize: 12),
                    ),
                  );
                }).toList(),
                cancelButton: CupertinoActionSheetAction(
                  onPressed: () => Navigator.pop(context),
                  child: const Text('取消'),
                ),
              );
            });
        break;
      default:
        break;
    }
  }

  @override
  Widget build(BuildContext context) {
    return BaseStoreContainer(builder: (context, theme, state, dispatch) {
      var appDebug = state.appConfigState!.appDebug;
      return Scaffold(
        backgroundColor: theme.body,
        appBar: AppBar(
          systemOverlayStyle: theme.systemOverlayStyleReverse,
          backgroundColor: theme.body,
          iconTheme: IconThemeData(color: theme.title, opacity: 1),
          title: Text(
            title,
            style: TextStyle(color: theme.title),
          ),
        ),
        body: ListView.separated(
          itemCount: appDebug?.length ?? 0,
          separatorBuilder: (BuildContext context, int index) {
            return const Divider(height: 1);
          },
          itemBuilder: (BuildContext context, int index) {
            AppDebugModel item = appDebug![index];
            return GestureDetector(
              onTap: () => onTap(context, item),
              child: ListTile(
                title: Text(
                  item.title,
                  style: TextStyle(color: theme.body),
                ),
                subtitle: subtitle(theme, item),
                tileColor: theme.title.withOpacity(0.8),
                trailing: trailing(theme, item),
              ),
            );
          },
        ),
      );
    });
  }
}
""";
